import 'package:inmotion_pro/config/r.dart';
import 'package:inmotion_pro/l10n/local.dart';
import 'package:inmotion_pro/pages/models/vehicle_model.dart';
import 'package:inmotion_pro/pages/others/custom_view/others/refresh_view.dart';
import 'package:inmotion_pro/routes/app_routes.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';
import '../../main/widgets/vehicle_item_view.dart';
import 'controller.dart';

// 车辆列表页面
class VehicleListView extends BaseGetView<VehicleListController> {
  VehicleListView({super.key});

  @override
  String? get title => local.vehicle_list;

  @override
  List<Widget>? get rightViews => [
        IconButton(
          icon: Image.asset(R.authApplicationInfoIcon,
              width: 20, color: LxCol.theme),
          onPressed: () {
            Get.toNamed(AppRoutes.VEHICLE_AUTH_APPLICATION_LIST);
          },
        )
      ];

  @override
  Widget buildBody(BuildContext context) {
    return Obx(
      () => Container(
        color: Colors.black,
        child: LxRefreshView(
          onRefresh: () => controller.onRefresh(),
          onLoadMore: () => Future.value(),
          enablePullUp: false,
          child: (controller.state.vehicleList.value?.isEmpty == true)
              ? LxEmptyView(emptyMessage: local.no_data_available)
              : ListView.builder(
                  addAutomaticKeepAlives: false,
                  physics: const AlwaysScrollableScrollPhysics(),
                  itemCount: controller.state.vehicleList.value?.length ?? 0,
                  itemBuilder: (context, index) {
                    VehicleModel item =
                        controller.state.vehicleList.value![index];
                    // 基本使用
                    return Padding(
                      padding: EdgeInsets.only(
                        top: CONTENT_MARGIN / 2,
                        bottom: CONTENT_MARGIN / 2,
                        left: CONTENT_MARGIN,
                        right: CONTENT_MARGIN,
                      ),
                      child: VehicleItemView(
                        model: item,
                        height: 150.w,
                        selectOnTap: (model) {
                          controller.toAuthorizedUsersOnTap(model);
                        },
                        deleteOnTap: (model) {
                          controller.deleteLocalVehicleOnTap(model);
                        },
                        showBanner: true,
                      ),
                    );
                  },
                ),
        ),
      ),
    );
  }
}
